﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;
using HZ.Supervise.Model.Enum;
using HZ.Supervise.Model.View;

namespace HZ.Supervise.Web.Enterprise
{
    public partial class StockAmountDetail : BasePage
    {
        IBLL_Company ic = HZ.Supervise.BLLFactory.IBLL_Company();
        IBLL_Area ia = BLLFactory.IBLL_Area(); 

        public StockAmountDetail()
        {

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager_CompanyPS_PageChanged(object sender, EventArgs e)
        {
            //AspNetPager_CompanyPS.CurrentPageIndex = 1; 
            BindData();

        }

        /// <summary>
        /// 绑定数据
        /// modify  by张雄  2011.5.4
        /// </summary>
        public void BindData()
        {
            SuperviseQuery vs = new SuperviseQuery();
            vs = Queryby();
            lblTitle.Text = string.Format("医院名称：{0}", vs.HospitalName);
            int t = 0;
            vs.Flag = "0";
            System.Data.DataTable dt = ic.GetTotalDetailByStock(vs, this.AspNetPager_CompanyPS.CurrentPageIndex, AspNetPager_CompanyPS.PageSize, out t);

            AspNetPager_CompanyPS.RecordCount = t;

            this.gvwPSLInfo.PageSize = AspNetPager_CompanyPS.PageSize;
            this.gvwPSLInfo.DataSource = dt;
            this.gvwPSLInfo.DataBind();
        }
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager_CompanyPS.CurrentPageIndex = 1;
        }
        /// <summary>
        /// 分页    县区
        /// by张雄
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void CompanyPSL_PS_PageChanged(object sender, EventArgs e)
        {
            BindData();

        }



        /// <summary>
        /// 导出
        /// modify  by  张雄    2011.5.5
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            SuperviseQuery vs = new SuperviseQuery();
            vs = Queryby();
            int t = 0;
            System.Data.DataTable dt = ic.GetTotalDetailByStock(vs, 1, 0, out t);
            ExportFile.Instance.ExportData(dt, gvwPSLInfo, this.Page);
        }



        /// <summary>
        /// 查询条件
        /// </summary>
        /// <returns></returns>
        private SuperviseQuery Queryby()
        {
            SuperviseQuery vs = new SuperviseQuery();

            vs = (SuperviseQuery)Session[Request.QueryString["sesid"]];
            vs.SortFields = " ProcureCatalogID";// OrderFileds.SelectedValue + " " + OrderType.SelectedValue;
            switch (vs.BackPage.ToLower())
            {
                case "hospital":
                    vs.ProcureCatalogID = "";
                    break;
                case "comps":
                    vs.ProcureCatalogID = "";
                    break;
                case "comsc":
                    vs.ProcureCatalogID = "";
                    break;
                case "area":
                    vs.ProcureCatalogID = ""; 
                    
                    string areaid = vs.AreaID.Substring(vs.AreaID.IndexOf("'") + 1, vs.AreaID.LastIndexOf("'") - vs.AreaID.IndexOf("'") - 1);
                    Area area = ia.GetArea(areaid);
                    lblTitle.Text = "当前查询地区：" + area.AreaName;
                    
                    break;
                case "goods":
                    break;
            }
            vs.ProductName = ""; 
            vs.CompanyName_SC = txtCompanyName_TB.Text.Trim();

            if (string.IsNullOrEmpty(vs.ProcureCatalogID))
            {
                vs.ProcureCatalogID = txtProcureCatalogID.Text.Trim();
            }
            if (HZ.Common.zhHansUtil.HaveChineseCode(txtProductName.Text.Trim()))
            {
                vs.ProductName = txtProductName.Text.Trim();
            }
            else
            {
                vs.PinyinCode = txtProductName.Text.Trim();
            }
             
            vs.MedicineModelName = txtMedicineModel.Text.Trim();
            vs.Pack = txtPack.Text.Trim();
            vs.AreaID = null;
            return vs;
        }



        protected void btnBack_Click(object sender, EventArgs e)
        {
            string url = Request.QueryString["returnUrl"];

            Response.Redirect(url);
        }

    }
}
